package com.itheima.rocketmq.rocketmqdemo.base.product;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;

import java.util.concurrent.TimeUnit;

/**
 * 单向发送消息：日志
 * @description:
 * @author: ycc
 * @time: 2021/3/24
 */
public class OnewayProducer {
    public static void main(String[] args) throws Exception {
//        1.创建消息生产者producer，并制定生产者组名
        DefaultMQProducer producer = new DefaultMQProducer("group3",false);
//        2.指定Nameserver地址
        producer.setNamesrvAddr("localhost:9876;localhost:9877");
//        3.启动producer
        producer.start();
        for (int i=0;i<10;i++){
//        4.创建消息对象，指定主题Topic、Tag和消息体
            Message msg = new Message("base3","Tag3","key3",("余长城单向消息"+i).getBytes());
//        5.发送消息
            producer.sendOneway(msg);
        }
//        6.关闭生产者producer
        producer.shutdown();
    }
}


